#include <iostream>
#include <math.h>

using namespace std;

void createSpirArr(int n,int A[][10]){
    int start,end,fix;
    int value=n*n;
    for(int i=n-1;i>=n/2;i--){
        start=i;
        end=n-1-i;
        fix=i;
        while(start>=end)
            A[fix][start--]=value--;

        start=i-1;
        end=n-1-i;
        fix=n-1-i;
        while(start>=end)
            A[start--][fix]=value--;

        start=n-i;
        end=i;
        fix=n-1-i;
        while(start<=end)
            A[fix][start++]=value--;

        start=n-i;
        end=i-1;
        fix=i;
        while(start<=end)
            A[start++][fix]=value--;

    }
}
int main() {

    int test=1;
    int R[test];//mang ket qua
    cin>>test;
    int t=1;
    int x=1,y=-2;//toa do can nhap vao de tim ra con so tuong ung
    int n;//dimension cua ma tran
    while(t<=test) {
        cin>>x;
        cin>>y;

        int max=fabs(x)>fabs(y)?fabs(x):fabs(y);
        n=2*max+1;

        //int value=1;
        //khoi tao ma tran ban dau-->de kiem tra
        int A[10][10];
        for(int i=0; i<=n; i++)
            for(int j=0; j<=n; j++)
                A[i][j]=0;


        //chuyen toa do x,y trong he Decartes sang toa do i,j cua ma tran
        int xArr=max-y;
        int yArr=max+x;

        //tao ma tran xoan oc tu n*n ->1 theo chieu kim dong ho
        createSpirArr(n,A);

        //xuat ma tran ra de kiem tra
        //for(int i=0;i<n;i++){
          //  cout<<endl;
            //for(int j=0;j<n;j++)
              //  cout<<A[i][j]<<"    ";
        //}

        //luu ket qua vao mang de sau nay xuat ra 1 luot
        R[t]=A[xArr][yArr];
        t++;

    }

    t=1;
    cout<<endl<<"Ket qua la: \n";
    while(t<=test)
        cout<<R[t++]<<endl;
    return 0;
}
